package com.sh.caryr.erp.controller.basis;


import com.sh.caryr.erp.entity.basis.PlatformSystemMapping;
import com.sh.caryr.erp.exception.ResultCode;
import com.sh.caryr.erp.exception.RestServiceException;
import com.sh.caryr.erp.service.IPlatformSystemMappingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * <p>
 * 平台系统商品映射表 前端控制器
 * </p>
 *
 * @author milkeeper
 * @since 2017-11-27
 */
@Controller
@RequestMapping("/erp/platformSystemMapping")
public class PlatformSystemMappingController {
    @Autowired
    private IPlatformSystemMappingService platformSystemMappingService;

    @RequestMapping(method = RequestMethod.GET)
    public List<PlatformSystemMapping> findPlatformSystemMappings() {
        return platformSystemMappingService.selectList(null);
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public PlatformSystemMapping findPlatformSystemMappingById(@PathVariable long id){
        PlatformSystemMapping platformSystemMapping = platformSystemMappingService.selectById(id);
        if (platformSystemMapping == null){
            throw new RestServiceException(HttpStatus.NOT_FOUND, ResultCode.ENTITY_NOT_FOUND);
        }
        return  platformSystemMapping;
    }

    @RequestMapping(method= RequestMethod.POST)
    public Object insertPlatformSystemMapping(@RequestBody PlatformSystemMapping platformSystemMapping) {
        return platformSystemMappingService.insert(platformSystemMapping) ? ("添加成功") : ("添加失败");
    }

    @RequestMapping(value = "/{id}",method=RequestMethod.PUT)
    public Object updatePlatformSystemMappingById(@PathVariable long id, @RequestBody PlatformSystemMapping platformSystemMapping) {
        platformSystemMapping.setId(id);
        return platformSystemMappingService.updateById(platformSystemMapping) ? ("修改成功") : ("修改失败");
    }

    @RequestMapping(value = "/{id}",method=RequestMethod.DELETE)
    public Object deletePlatformSystemMappingById(@PathVariable long id) {
        return platformSystemMappingService.deleteById(id) ? ("删除成功") : ("删除失败");
    }

}
